package com.kavin.aidl;

import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

public class SecondActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);


        Intent intent = new Intent(this, MyService.class);
        bindService(intent, connection, BIND_AUTO_CREATE);

    }

    private ServiceProxy serviceProxy;

    ServiceConnection connection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            serviceProxy = ServiceProxy.Stub.asInterface(service);
            Log.d("------TAG", "onServiceConnected2: "+name.toString());
        }

        @Override
        public void onServiceDisconnected(ComponentName name) { // 远程 remote
            Log.d("------TAG", "onServiceDisconnected2: ");
        }
    };

    public void click2(View view) {
        try {
            String string = serviceProxy.setString("client2");
            Log.d("------TAG", "click2: " + string);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }
}
